<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        let validator = {
            set(obj, prop, value) {
                if (prop === 'age') {
                    if (!Number.isInteger(value)) {
                        throw new TypeError('The age is not integer!')
                    }
                    if (value > 200) {
                        throw new RangeError('The age too large')
                    }
                } else {
                    throw new TypeError('The prop is not allowed')
                }

                // 保存满足条件的属性
                obj[prop] = value
            }
        }

        let person = new Proxy({}, validator);
        person.age = 100;
        // person.age = 300;
        // person.age = 'wang';
        console.log(person.age)
    </script>
</head>
<body>

</body>
</html>